package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Foodtype;
import com.restaurant.service.FoodtypeService;

public class FoodtypeServiceImpl implements FoodtypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Foodtype addOrModify( Foodtype objFoodtype ) {
       return ( Foodtype ) hibernateTemplate.merge( objFoodtype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Foodtype deleteRecord( Foodtype objFoodtype ) {
       hibernateTemplate.delete( objFoodtype );
       return objFoodtype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Foodtype modifyRecord( Foodtype objFoodtype ) {
       return ( Foodtype ) hibernateTemplate.merge( objFoodtype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Foodtype> loadAll() {
       return (List<Foodtype>)hibernateTemplate.findByNamedQuery( "Foodtype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Foodtype loadByPrimaryKey( Long primaryKey ) {
       return (Foodtype) hibernateTemplate.get( Foodtype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Foodtype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Foodtype> loadByHql(String query) {
       return ( List<Foodtype> ) hibernateTemplate.find( query );
   }
}